<template>
    <div>
        <h3>门店增加</h3>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">门店名称</td>
                    <td>
                        {{ info.shopName }}
                    </td>
                </tr>
                <tr>
                    <td align="right">分店名称</td>
                    <td>
                        {{ info.brancName }}
                    </td>
                </tr>
                <tr>
                    <td align="right">门店图片</td>
                    <td>
                        <img :src="info.photo" width="100" height="100">
                    </td>
                </tr>
                <tr>
                    <td align="right">开业时间</td>
                    <td>
                        {{ info.openTime }}
                    </td>
                </tr>
                <tr>
                    <td align="right">门店状态</td>
                    <td>
                        {{ info.state == true ? "开启" : "禁用" }}
                    </td>
                </tr>
                <tr>
                    <td align="right">门店特色</td>
                    <td>
                        {{ info.tese.toString() }}
                    </td>
                </tr>
                <tr>
                    <td align="right">联系电话</td>
                    <td>
                        {{ info.tel }}
                    </td>
                </tr>
                <tr>
                    <td align="right">门店简介</td>
                    <td>
                        {{ info.desc }}
                    </td>
                </tr>
                <tr>
                    <td align="right">门店地址</td>
                    <td>
                        {{ info.addressName }}
                    </td>
                </tr>
                <tr>
                    <td align="right">门店类型</td>
                    <td>
                        {{ info.shopType }}
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import axios from 'axios';
import { useRouter, useRoute } from 'vue-router';
const router = useRouter();
const route = useRoute();
onMounted(() => {
    BangaddRess();
    FindType();
})
//反填
const FindType = () => {
    axios({
        url: '/api/Shops/GetShopItemByidNew',
        method: 'get',
        params: {
            id: route.query.id
        }
    })
        .then((res) => {
            console.log(res);
            Object.assign(info, res.data)
        })
        .catch((err) => {
            console.log(err);

        })
}
//下拉框
let type: any = ref([]);
const BangaddRess = () => {
    axios({
        url: '/api/Shops/BangShopAddress',
        method: 'get',
    })
        .then((res) => {
            console.log(res);
            type.value = res.data;
        })
        .catch((err) => {
            console.log(err);
        })
}
//门店修改
let info: any = reactive({
    "shopId": route.query.id,
    "shopName": "",
    "brancName": "",
    "photo": "",
    "openTime": "",
    "state": true,
    "tese": [],
    "tel": "",
    "desc": "",
    "addressId": '',
    "shopType": "",
})
const Add = () => {
    if (info.shopName == "") {
        alert('门店名称不能为空')
        return;
    }
    if (info.brancName == "") {
        alert('分店名称不能为空')
        return;
    }
    if (info.photo == "") {
        alert('图片必填')
        return;
    }
    if (info.openTime == "") {
        alert('开业时间不能为空')
        return;
    }
    if (info.tese.length == "") {
        alert('门店特色必选')
        return;
    }
    if (info.tel == "") {
        alert('联系电话不能为空')
        return;
    }
    if (info.desc == "") {
        alert('简介不能为空')
        return;
    }
    if (info.desc.length > 50) {
        alert('简介长度不能超过50')
        return;
    }
    if (info.addressId == "") {
        alert('地址必选')
        return;
    }
    if (info.shopType == "") {
        alert('酒店类型必选')
        return;
    }
    info.tese = info.tese.toString();
    axios({
        url: '/api/Shops/UpdateShop',
        method: 'put',
        data: info
    })
        .then((res) => {
            console.log(res);
            if (res.data == -1) {
                alert('门店名称重复')
                return;
            }
            if (res.data > 0) {
                alert('修改成功')
                router.push('/listshop')
                return;
            }
            else {
                alert('修改失败')
                return;
            }
        })
        .catch((err) => {
            console.log(err);

        })
}
</script>

<style scoped></style>